/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BusinessLogic;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author Tran anh
 * @version 1.0
 */
public class BackGroundUtility {

    /**
     * path to specify file where contain String path to background
     */
    private static String nameFile = "background.txt";

    /**
     * Get a string a path to background.
     * get information from file background.txt
     * @return String is path of background
     */
    public static String getImage() {
        // Stream to read file
        try {
            // Open an input stream
            File file = new File(nameFile);
            if (file.exists()) {
                FileInputStream fstream = new FileInputStream(file);
                // Get the object of DataInputStream
                DataInputStream in = new DataInputStream(fstream);
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
                String strLine = br.readLine();

                return strLine;
            }

        } // Catches any error conditions
        catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
    /**
     * store path of new background into background.txt
     * @param path is path of new Background
     */
    public static void setImage(String path) {
        BufferedWriter out = null;
        try {
            out = new BufferedWriter(new FileWriter(nameFile));
            out.write(path);
            out.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
